package cn.tedu.oop;

import java.util.Random;
import java.util.Scanner;

/**本类用于复习面向对象的相关知识*/
public class Testoop {
    public static void main(String[] args) {
        System.out.println("请您输入宠物名称");
        String name = new Scanner(System.in).nextLine();
        Pet c = new Cat(name);
//        Cat c1 = (Cat) c;//向下造型，可以使用子类的特有功能
        System.out.println("按回车执行");
        while(true){
            new Scanner(System.in).nextLine();
            int r = new Random().nextInt(5);
            switch (r){
                case 0: c.feed();break;
                case 1: c.play();break;
                default:c.punish();break;
            }
        }
    }
}
class Pet{
    String name;
    int full;
    int happy;

    public Pet(String name, int full, int happy) {
        this.name = name;
        this.full = full;
        this.happy = happy;
    }

    public Pet(String name) {
        //实际上会触发全参构造 ，名字自定义，其他的两个都是规定的默认值
        this(name,50,50);
    }
    public void feed(){
        if (full == 100){
            System.out.println(name+"已经吃饱啦");
            return;
        }
        System.out.println("喂食"+name);
        full+=10;
        System.out.println("饱食度："+full);
    }
    public void play(){
        if (full == 0){
            System.out.println(name+"已经饿的玩不动了~");
            return;
        }
        System.out.println("陪"+name+"玩耍");
        happy+=10;
        full-=10;
        System.out.println("快乐度"+happy);
        System.out.println("饱食度"+full);
    }
    public void punish(){
        System.out.println("打"+name+"的屁屁，哭叫声："+cry());
        happy-=10;
        System.out.println(happy);
    }

    public String cry() {
        return "此处有哭叫声";
    }
}
class Cat extends Pet{

    public Cat(String name) {
        super(name);
    }
    @Override
    public String cry(){
        return "喵！~";
    }
}
